package com.rtx.model.dto.response.auth;

/**
 * @author Zy
 */
public class ResponseModel {

    /**
     * 失败code
     */
    public static final String FAILED_CODE = "400";

    /**
     * 成功code
     */
    public static final String SUCCESS_CODE = "200";

    /**
     * 成功 msg
     */
    public static final String SUCCESS_MSG = "SUCCESS";

    private String returnCode;

    private String returnMgr;

    private Object data;

    private int total;

    private String token;

    private String spiltChars;

    private String userLanguage;

    public ResponseModel() {
    }


    public ResponseModel(String returnCode, String msg) {
        this.returnCode = returnCode;
        this.returnMgr = msg;
    }

    private ResponseModel(String returnMgr, String returnCode, Object data, int total) {
        this.returnCode = returnCode;
        this.returnMgr = returnMgr;
        this.data = data;
        this.total = total;
    }

    private ResponseModel(String returnMgr, String returnCode, Object data) {
        this.returnCode = returnCode;
        this.returnMgr = returnMgr;
        this.data = data;
    }


    @Override
    public String toString() {
        return "Response [returnCode=" + returnCode + ", returnMgr=" + returnMgr + ", data=" + data + ", total=" + total + ", token=" + token + "]";
    }

    /**
     * 调用成功后返回结果（不需要返回对象）
     *
     * @return
     */
    public static ResponseModel success() {
        return new ResponseModel(SUCCESS_CODE, SUCCESS_MSG);
    }

    /**
     * 调用成功后返回结果(需要分页)
     *
     * @return
     */
    public static ResponseModel successPage(Object data, int total) {
        return new ResponseModel(SUCCESS_MSG, SUCCESS_CODE, data, total);
    }

    /**
     * 调用成功后返回结果(不需要分页)
     *
     * @return
     */
    public static ResponseModel successBean(Object data) {
        return new ResponseModel(SUCCESS_MSG, SUCCESS_CODE, data);
    }

    /**
     * 调用成功后返回结果
     *
     * @param returnMgr 错误提示信息
     * @return
     */
    public static ResponseModel fail(String returnCode, String returnMgr) {
        return new ResponseModel(returnCode, returnMgr);
    }

    public static ResponseModel fail(String returnMgr) {
        return new ResponseModel(FAILED_CODE, returnMgr);
    }

    public void setReturnMgr(String code, Object... params) {
//        ApplicationContext applicationContext = ApplicationContextRegister.getApplicationContext();
//        LanguageConfig languageConfig = applicationContext.getBean(LanguageConfig.class);
//        String message = languageConfig.getLocaleMessage(code, params);
//        this.returnMgr = message;
    }

    public String getReturnCode() {
        return returnCode;
    }

    public void setReturnCode(String returnCode) {
        this.returnCode = returnCode;
    }

    public String getReturnMgr() {
        return returnMgr;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getSpiltChars() {
        return spiltChars;
    }

    public void setSpiltChars(String spiltChars) {
        this.spiltChars = spiltChars;
    }

    public String getUserLanguage() {
        return userLanguage;
    }

    public void setUserLanguage(String userLanguage) {
        this.userLanguage = userLanguage;
    }
}
